home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Portable Patmos 1.1 / patmos-src / src / write.c < prev   
Encoding:
C/C++ Source or Header  |  1996-01-19  |  700 b   |  34 lines  |  [TEXT/KAHL]

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <errno.h>
  5. #include "crtlocal.h"
  6.  
  7. int write(int fd, const void *buf, unsigned size)
  8.     {
  9.     OSErr err;
  10.     IOParam pb;
  11.     if (crt_fd_tab[fd].flags & O_PIPE)
  12.         {
  13.         if ((crt_fd_tab[fd].fd&-256) == 100<<8) return cwrite(crt_fd_tab[fd].fd&255,buf,size);
  14.         return writepipe(fd, (char *)buf, size);
  15.         }
  16.     else if (crt_fd_tab[fd].flags & O_CATALOG)
  17.         {
  18.         errno = EISDIR;
  19.         return -1;
  20.         }
  21.     else
  22.         {
  23.         pb.ioCompletion = 0;
  24.         pb.ioRefNum = crt_fd_tab[fd].fd;
  25.         pb.ioReqCount = size;
  26.         pb.ioPosMode = fsAtMark;
  27.         pb.ioBuffer = (void *)buf;
  28.         PBWriteSync((ParmBlkPtr)&pb);
  29.         err = errtran(pb.ioResult);
  30.         return pb.ioActCount;
  31.         }
  32.     }
  33.  
  34.